package org.bravo369.inflightxt.utils;

import java.util.Vector;

import org.bravo369.inflightxt.utils.RestClient.RequestMethod;
import org.json.JSONArray;

public class PositionUploader extends Thread {
  private Vector<Position> positions;

  public PositionUploader(Vector<Position> positions) {
    this.positions = positions;
  }

  private void Upload() {
    Globals globals = Globals.getInstance();
    JSONArray data = new JSONArray();
    for (Position position: positions) {
      data.put(position.toJSON());
    }
    RestClient client = new RestClient(globals.apiUri);
    client.AddParam("method", "positions");
    client.AddHeader("Authorization", globals.authKey);
    client.AddBody(data.toString());
    try {
      client.Execute(RequestMethod.POST);
      int response = client.getResponseCode();
      response = response;
    } catch (Exception e) {
      // TODO Auto-generated catch block
      int response = client.getResponseCode();
      e.printStackTrace();
    }
  }

  public void run() {
    Upload();
  }
}
